package com.better.common.utils;

import com.better.common.base.ServiceResponse;

/**
 * Created by Administrator on 2017/11/8.
 */
public class ServiceResponseHandle {

    /**
     * 成功
     * @param data
     * @return ServiceResponse
     */
    public static <T> ServiceResponse<T> success(T data) {
        ServiceResponse<T> wrs = new ServiceResponse<T>();
        wrs.setSuccess(true);
        wrs.setCode("200");
        wrs.setData(data);
        return wrs;
    }

    public static <T> ServiceResponse<T> success(T data,String msg) {
        ServiceResponse<T> wrs = new ServiceResponse<T>();
        wrs.setSuccess(true);
        wrs.setData(data);
        wrs.setMessages(msg);
        wrs.setCode("200");
        return wrs;
    }
    /**
     * 失败
     * @param msg 失败消息
     * @return ServiceResponse
     */
    public static ServiceResponse failed(String msg) {
        ServiceResponse wrs = new ServiceResponse();
        wrs.setMessages(msg);
        wrs.setSuccess(false);
        return wrs;
    }
    /**
     * 失败
     * @param code 失败码
     * @param msg 失败消息
     * @return ServiceResponse
     */
    public static ServiceResponse failed(String code, String msg) {
        ServiceResponse wrs = failed(msg);
        wrs.setCode(code);
        return wrs;
    }
}
